﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using NCI.EasyObjects;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using CMS.BLL.Entity;
using CMS.DAL;

namespace CMS.BLL
{
    public class Region
    {
        #region Common
        public eRegion   Data;

        public Region()
        {
            Data = new eRegion();
		}

        ~Region()
        {
		}

		public virtual void Dispose()
        {
		}

        public int DeleteById(int ID)
        {
            int nResult = 0;
           cRegion objDAL = new cRegion();
            try
            {
                objDAL.LoadByPrimaryKey(ID);
                objDAL.MarkAsDeleted();
                objDAL.Save();
                nResult = ID;
            }
            catch
            {
                nResult = 0;
            }
            return nResult;
        }

        public void LoadById(int ID)
        {
           cRegion objDAL = new cRegion();
            objDAL.LoadByPrimaryKey(ID);
            ConvertData(objDAL);
        }

        public int Insert()
        {
            int nResult = 0;
           cRegion objInfor = new cRegion(); 
            try
            {
                objInfor.AddNew();
                this.MappingData(objInfor);
                objInfor.Save();
                nResult = objInfor.RegionID ;
            }
            catch
            {
                nResult = 0; 
            }
            return nResult;
        }

        public int Update(int ID)
        {
            int nResult = 0;
           cRegion objInfor = new cRegion();
            try
            {
                objInfor.LoadByPrimaryKey(ID);
                this.MappingData(objInfor);
                objInfor.Save();
                nResult = ID; 
            }
            catch
            {
                nResult = 0; 
            }
            return nResult;
        }

        private void MappingData(cRegion objInfor)
        {
            objInfor.RegionName1 = Data.RegionName1;
            objInfor.RegionName2 = Data.RegionName2;
            objInfor.RegionName3 = Data.RegionName3;
            objInfor.CountryID = Data.CountryID;
        }

        private void ConvertData(cRegion objInfor)
        {
            Data.RegionName1 = objInfor.RegionName1;
            Data.RegionName2 = objInfor.RegionName2;
            Data.RegionName3 = objInfor.RegionName3;
            Data.CountryID = objInfor.CountryID;
        }
        public DataTable GetALL()
        {
            DataTable tbResult = new DataTable();
            cRegion objDAL = new cRegion();
            tbResult = objDAL.GetALL();
            return tbResult;
        }
        public DataTable SearchByCountry(int Country)
        {
            DataTable tbResult = new DataTable();
            cRegion objDAL = new cRegion();
            tbResult = objDAL.SearchByCountry(Country);
            return tbResult;
        }
        #endregion
    }
}
